<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
if($_RQ['op']=='list'){
	//搜索
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if($_RQ['title']){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 15;
	$total='';
	$list=pdo_getslice('jy_wuliu_level',$params,array($pindex,$psize),$total,$fields);
	$return['list']=$list?$list:array();
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			'0'=>array('op'=>'list','title'=>'会员等级列表'),
		),
		'list'=>array('data'=>'list','delall'=>false,'list'=>array(
			array('name'=>'id','title'=>'ID','type'=>'string'),
			array('name'=>'title','title'=>'名称','type'=>'string'),
			array('name'=>'money','title'=>'费用','type'=>'string'),
		)
		),
		'search_one'=>array('name'=>'title','add_op'=>'edit')
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='edit'){
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_wuliu_level',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
	}else{
		$item=array();
	}
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'desc'=>'会员等级详情',
		'tabs'=>array(
			array('op'=>'list','title'=>'会员等级列表'),
			array('op'=>'edit','title'=>'会员等级详情'),
		),
		'edit'=>array(
			array('type'=>'string','title'=>'名称','name'=>'title', 'help'=>'' ),
			array('type'=>'string','title'=>'费用','name'=>'money', 'help'=>'只能填写整数！' ),
			array('type'=>'switch','title'=>'是否显示','name'=>'status','help'=>'' ),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$post=get_postdata();
	if(!intval($post['money'])){
		exi('请填写费用，并且是整数！','error');
	}
	$data=array(
		'title'=>trim($post['title']),
		'money'=>intval($post['money']),
		'status'=>intval($post['status']),
	);
	$id=intval($post['id']);
	if($id){
		pdo_update('jy_wuliu_level',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		pdo_insert('jy_wuliu_level',$data);
	}
	exi('保存成功！','','list');
}
?>